<template>
	<view class="body">
		<paper-left-popup @hide="hidepopup" @addfriend="addFriend" @clear="clear" :show="show"></paper-left-popup>
		<!-- 小纸条列表 -->
		<block v-for="(item, index) in list" :key="index">
			<paper-list :item="item"></paper-list>
		</block>
		<!-- 上拉加载 -->
		<load-more :loadText="loadText"></load-more>
	</view>
</template>

<script>
	import paperList from '../../components/paper/paper-list.vue'
	import loadMore from '../../components/common/load-more.vue'
	import paperLeftPopup from '../../components/paper/paper-left-popup.vue'
	export default {
		data() {
			return {
				show: false,
				loadText: '上拉加载更多',
				list: [
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '11'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '0'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '2'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '11'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '0'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '2'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '11'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '0'
					},
					{
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '10:21',
						data: '我是信息',
						noreadnum: '2'
					},
				]
			}
		},
		components: {
			paperList,
			loadMore,
			paperLeftPopup,
		},
		onPullDownRefresh() { // 监听下拉刷新
			this.getData()
		},
		onReachBottom() { // 页面上拉触底事件处理函数
			this.loadMore()
		},
		onNavigationBarButtonTap(e) { // 监听原生标题导航栏点击事件
			// console.log(JSON.stringify(e))
			switch(e.index) {
				case 0:
					this.User.navigate({
						url: '../user-list/user-list',
					}, 'navigateTo')
					console.log('1111')
					this.hidepopup()
					break
				case 1:
					this.showpopup()
					break
			}
		},
		methods: {
			// 操作菜单
			addFriend() { // 加糗友
				console.log('加糗友')
				this.hidepopup()
			},
			clear() { // 清除缓存
				console.log('清除缓存')
				this.hidepopup()
			},
			hidepopup() { // 隐藏显示操作菜单
				this.show = false
			},
			showpopup() {
				this.show = true
			},
			getData() { // 获取数据
				setTimeout(() => {
					// 服务器获取数据
					let arr = [
						{
							userpic: '../../static/logo.png',
							username: '昵称',
							time: '10:21',
							data: '我是信息',
							noreadnum: '0'
						},
						{
							userpic: '../../static/logo.png',
							username: '昵称',
							time: '10:21',
							data: '我是信息',
							noreadnum: '11'
						},
						{
							userpic: '../../static/logo.png',
							username: '昵称',
							time: '10:21',
							data: '我是信息',
							noreadnum: '0'
						},
					]
					// 赋值
					this.list = arr
					// 关闭 下拉刷新
					uni.stopPullDownRefresh()
				}, 2000)
			},
			loadMore() { // 上拉加载
				if (this.loadText !== '上拉加载更多') return
				// 修改状态
				this.loadText = '加载中...'
				// 获取数据
				setTimeout(() => {
					// 获取完成
					let obj = {
						userpic: '../../static/logo.png',
						username: '昵称',
						time: '13:21',
						data: '我是信息',
					}
					this.list.push(obj)
					this.loadText = '上拉加载更多'
				}, 1000)
				// this.loadText = '没有更多数据了'
			}
		}
	}
</script>

<style lang="scss" scoped>
.body {
	padding: 0 20rpx;
	position: relative;
}
</style>
